package com.fr.web.core.service;

import com.fr.base.core.json.JSONArray;
import com.fr.base.xml.BaseXMLUtils;
import com.fr.data.DBFeedback;
import com.fr.data.DBManipulation;
import com.fr.report.script.Calculator;
import com.fr.report.script.ParameterMapNameSpace;
import com.fr.web.core.WebUtils;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DBCommitService extends NoSessionIDOPService
{
  private static DBCommitService service = null;
  public static final String ARG_XMLCONF = "xmlconf";

  public static DBCommitService getInstance()
  {
    if (service == null)
      service = new DBCommitService();
    return service;
  }

  public boolean accept(String paramString)
  {
    return "dbcommit".equals(paramString);
  }

  public void process(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    String str = WebUtils.getHTTPRequestParameter(paramHttpServletRequest, "xmlconf");
    DBManipulation localDBManipulation = (DBManipulation)BaseXMLUtils.readStringAsXMLable(str, new DBManipulation());
    Calculator localCalculator = Calculator.createCalculator();
    localCalculator.pushNameSpace(ParameterMapNameSpace.create(WebUtils.createTemplateMap(paramHttpServletRequest)));
    localCalculator.pushNameSpace(ParameterMapNameSpace.create(WebUtils.parameters4SessionIDInfor(paramHttpServletRequest)));
    DBFeedback localDBFeedback = localDBManipulation.commit2dbAndFeedback(localCalculator);
    PrintWriter localPrintWriter = WebUtils.createPrintWriter(paramHttpServletResponse);
    localPrintWriter.write((localDBFeedback != null) ? localDBFeedback.toJSON().toString() : "success");
    localPrintWriter.flush();
    localPrintWriter.close();
  }
}